package com.pcbly.web.components.utils.security;

import java.security.MessageDigest;

public class MD5 {
	public static String getMD5(byte[] password) {

        MessageDigest md = null;

        try {
            // first create an instance, given the provider
            md = MessageDigest.getInstance("MD5");
        } catch (Exception e) {
//            log.error("Exception: " + e);

            return password.toString();
        }

        md.reset();

        // call the update method one or more times
        // (useful when you don't know the size of your data, eg. stream)
        md.update(password);

        // now calculate the hash
        byte[] encodedPassword = md.digest();

        StringBuffer buf = new StringBuffer();

        for (int i = 0; i < encodedPassword.length; i++) {
            if ((encodedPassword[i] & 0xff) < 0x10) {
                buf.append("0");
            }

            buf.append(Long.toString(encodedPassword[i] & 0xff, 16));
        }

        return buf.toString();
	}
	public static void main(String[] args){
		String t=getMD5("admin".getBytes());
		System.out.println(t);
		t=getMD5("11111111".getBytes());
		System.out.println(t);
	}
}
